/**
 * Copyright (C) 2010 DustedPixels.com
 */
package com.dustedpixels.cirt.model.cpu.z80;

import com.dustedpixels.cirt.model.core.Circuit;
import com.dustedpixels.cirt.model.core.In;
import com.dustedpixels.cirt.model.core.Out;
import com.dustedpixels.cirt.model.core.Pins;
import com.dustedpixels.cirt.model.core.Script;

/**
 * Calculates index offset.
 *
 * @author Michal Pociecha-Los (micapolos@gmail.com)
 */
@Circuit
public final class OffsetDecoder {
  @In @Pins(16) public int indexIn;
  @In @Pins(8) public int offsetIn;
  @Out @Pins(16) public int indexOut;
  
  @Script
  public void decode() {
    // Casting offsetIn to byte, and then again to int will result in int 
    // offset value from -128..127 range.
    indexOut = (indexIn + (int) (byte) offsetIn) & 0xFFFF;
  }
}
